<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .big {
            height: 550px;
            width: 500px;
            margin: 20px auto;
            position: relative;
            overflow: hidden;
        }

        img {
            width: 550px;
            height: 500px;
            display: block;
        }

        .small {
            height: 50px;
            width: 500px;
            box-sizing: border-box;
            border: 1px solid black;
        }

        .small input {
            height: 48px;
            width: 400px;
            border: none;
            font-size: 24px;
        }

        .small span {
            height: 48px;
            width: 98px;
            background-color: rgb(252, 228, 232);
            text-align: center;
            line-height: 50px;
            display: block;
            float: right;
            font-size: 24px;
            cursor: pointer;
            /* box-sizing: border-box; */

        }

        li {
            height: 30px;
            font-size: 30px;
            position: absolute;
            top: 0;
            left: 400px;
            white-space: nowrap;
        }
    </style>
</head>

<body>
    <div class="big">
        <img
            src="https://s.cn.bing.net/th?id=OIP-C.3HkXsJ4gYVKfim1lEudQrgHaHa&w=250&h=250&c=8&rs=1&qlt=90&o=6&dpr=1.25&pid=3.1&rm=2">
        <div class="small">
            <input type="text">
            <span class="btn">发送</span>
        </div>
    </div>

    <script>

        const obig = document.querySelector('.big');
        const inp = document.querySelector('input');
        const obtn = document.querySelector('.btn');

        obtn.onclick = function () {
            const oinp = inp.value;
            if (oinp === '') {
                alert('输入框不能为空')
                return
            }

            const lis = document.createElement('li');

            lis.innerHTML = `${oinp}`;

            obig.appendChild(lis);

            lis.style.top = suiji(0, 255) + 'px';

            const aa = suiji(0, 255);

            const bb = suiji(0, 255);

            const cc = suiji(0, 255);

            lis.style.color = `rgba(${aa},${bb},${cc})`;

            let t;

            let a = -lis.offsetWidth;

            t = setInterval(function () {
                a++;
                lis.style.left = a + 'px';

                if (a >= obig.offsetWidth) {
                    lis.remove();
                    clearInterval(t);
                }
            }, 10)
        }




        function suiji(min, max) {
            return Math.round(Math.random() * (max - min) + min)
        }


    </script>

</body>

</html>